﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TouTiao.aspx.cs" Inherits="WAD.WEB.Client2.Page.TouTiao" %>

<%=html %>
<script src="../js/jquery-2.1.4.min.js" type="text/javascript"></script>
<script src="gethtml.aspx?source=toutiao&id=<%=json_id %>" type="text/javascript"></script>
<script type="text/javascript">
    $(function () {
        load();
        loadTitle();
        $(".article__header").css("display", "none");
        $(".body-placeholder").css("display", "none");
        $(".comments-container").css("display", "none");
        $(".comments-container").html("");
    });
    function load() {
        if ($(".article-container .title"))
            $(".article-container .title").text(json.data.title);
        if ($(".article-content"))
            $(".article-content").html(json.data.content);
        else {
            $("#main").html(json.data.content);
        }
    }

    function loadTitle() {
        var arrList = new Array();
        var i = 0;
        $(".article-content").find("img").each(function () {
            if (i < 8 && $(this).width() > 200) {
                arrList[i] = $(this).attr("src");
                i++;
            }
        });
        Set(json.data.title, arrList);
    }

    //设置title,logo
    var logoItemHtml = '' + '<div class="col-xs-3"><img class = "logoItem" src="{src}" /></div>';
    function Set(title, imgList) {
        $_p("#title").val(title);

        // 默认第一张图片为头图
        if (imgList.length > 0) {
            $_p(".logo").attr("src", imgList[0]);
        }
        $(imgList).each(function () {
            $_p("#imgList").append(logoItemHtml.replace(/{src}/, this));
        });

        // 候选图片点击事件
        $_p(".logoItem").off("click");
        $_p(".logoItem").on("click", function () {
            $_p(".logo").attr("src", $(this).attr("src"));
        });
    }

    function js_date_time(unixtime) {
        var timestr = new Date(parseInt(unixtime) * 1000);
        var datetime = timestr.toLocaleString().replace(/年|月/g, "-").replace(/日/g, " ");
        return datetime.substring(5);
    }

    function $_p(id) {
        return $(id, window.parent.document);
    }
</script>
